﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.Center;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal.PartyRepresentative
{
    public partial class MeetingDetail : PortalPage
    {
        /// <summary>
        /// 会议ID
        /// </summary>
        private string MeetngID
        {
            get
            {
                return this.Request["id"] ?? "null";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        public void LoadData()
        {
            var meetting = DB.PartyRepresentativeMeetings.Find(MeetngID);
            if (meetting == null)
            {
                Response.Redirect("~/default.aspx");
            }
            var studio = DB.PartyRepresentativeStudios.Find(meetting.StudioID);
            if (studio == null)
            {
                Response.Redirect("~/default.aspx");
            }
            litTitle.Text = meetting.Title;
            litStudioName.Text = string.Format("<a href='StudioInfo.aspx?StudioID={0}'>{1}</a>", meetting.StudioID, studio.StudioName); 
            litRepresentatives.Text = GetPartyRepresentativeJoin(MeetngID);
            litTime.Text = Convert.ToDateTime( meetting.BeginTime).ToString("yyyy-MM-dd HH:mm")+" 至 "+ Convert.ToDateTime(meetting.EndTime).ToString("yyyy-MM-dd HH:mm");
            litAddress.Text = meetting.Address;
            litContent.Text = meetting.Content;

        }

        public string GetPartyRepresentativeJoin(string meetingId)
        {
            var q = DB.PartyRepresentativeMeetingJoins.Where(a => a.MeetingID == meetingId);
            var names = new List<string>();
            foreach (var item in q)
            {
                var join = DB.PartyRepresentativeInfos.Find(item.RepresentativeID);
                if (join != null)
                {
                    names.Add(join.UserName);
                }
            }
            return   string.Join(",", names.ToArray()) ;
        }
    }
}